package com.alarmgame.server;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;

import android.util.Log;

public class Server implements Runnable {
	public static final String SERVERIP = "127.0.0.1"; // 'Within' the emulator!
    public static final int SERVERPORT = 4444;
    private ServerSocket serverSocket;
    
	public void run() {
		try {
			serverSocket = new ServerSocket(SERVERPORT);
			while (true) {
				Socket client = serverSocket.accept();
				try {
                    BufferedReader in = new BufferedReader(new InputStreamReader(client.getInputStream()));
                    String line = null;
                    while ((line = in.readLine()) != null) {
                        Log.d("ServerActivity", line);	                            
                    }
                    if(line != null){
                    	 if(line.equals("1")){	                        
	                        	break;
	                        }
                    }
                } catch (Exception e) {	                        	                          
                    Log.d("ServerActivity", e.getMessage());                    
                }
			}					
		} catch (IOException e) {
			Log.d("ServerActivity", e.getMessage());            
		}

	}
}
